package com.chen.servlet;/*
package com.chen.servlet;

import com.chen.service.UserService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/deleteUser")
public class DeleteUserServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String phone = req.getParameter("phone");
        if(phone == null || phone == ""){
            //跳转到错误页面，客户端传递有误
            req.setAttribute("errorMsg", "phone的值为空");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        }
        try {
            int result = userService.updateDeleteByPhone(phone);
            if(result > 0){
                //如果删除成功，则跳转(转发)到 /showFlight 页面
                resp.sendRedirect("index.jsp");
            }else{
                //如果删除失败，则跳转(转发)到 error.jsp 页面
                req.setAttribute("errorMsg", "删除失败");
                req.getRequestDispatcher("error.jsp").forward(req, resp);
            }
        } catch (Exception e){
            e.printStackTrace();
            req.setAttribute("errorMsg", "系统异常");
            req.getRequestDispatcher("error.jsp").forward(req, resp);
        }
    }
}
*/
